//-------------------------------------------------------
// Copyright (c) 
// All rights reserved.
//
// File Name: WndForIPC.h
// File Des: 窗口消息进程内/间通信
// File Summary:
// Cur Version: 1.0
// Author:lzlong
// Create Data:2023-8-10
// History:
//         <Author>    <Time>        <Version>      <Des>
//      lzlong        2023-8-10     1.0
//-------------------------------------------------------
#pragma once
#include "MsgWindow.h"

class IIPCWndCallBack;
class CWndForIPC : public CMsgWindow
{
public:
    CWndForIPC(const std::wstring& strWindowName, bool bRecSameSvrNameMsg = true);

    ~CWndForIPC(void);

    int set_handler(IIPCWndCallBack* _p_callback);

protected:
    virtual LRESULT ProcessWndMessage(UINT msg, WPARAM wParam, LPARAM lParam);

    IIPCWndCallBack* m_pCallback;
};

#if 0
void TestIPC()
{
    CWndForIPC MsgIPC(L"WndIPC");
    WndIPCCallback* pcallback = new WndIPCCallback;
    MsgIPC.set_handler(pcallback);
    ::PostMessage(MsgIPC.GetHandle(), WM_USER + 0x45, 5, 2);
    ::SendMessage(MsgIPC.GetHandle(), WM_USER + 0x47, 45, 52);

    std::wstring strLog = L"data msg";
    wchar_t* pBuffer = new wchar_t[strLog.length() + 2];
    memcpy(pBuffer, strLog.c_str(), 2 * strLog.length() + 2);
    pBuffer[strLog.length()] = 0;

    COPYDATASTRUCT cds;
    cds.dwData = 53;
    cds.cbData = 2 * strLog.length() + 1;
    cds.lpData = pBuffer;
    ::SendMessage(MsgIPC.GetHandle(), WM_COPYDATA, 0, (LPARAM)&cds); //  WM_COPYDATA 必须是sendmessage

   /* {
        std::string strLog = "copy data msg";
        char* pBuffer = new char[strLog.length() + 2];
        memcpy(pBuffer, strLog.c_str(), strLog.length());
        pBuffer[strLog.length()] = 0;

        COPYDATASTRUCT cds;
        cds.dwData = 53;
        cds.cbData = strLog.length() + 1;
        cds.lpData = pBuffer;
        ::SendMessage(g_pRemoteIpc->getHandle(), WM_COPYDATA, 0, (LPARAM)&cds);
        delete pBuffer;
    }*/

    delete pBuffer;
    delete pcallback;
}
#endif